package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.goods.wx.WxGoodsCategoryData;
import com.cskaoyan.bean.goods.wx.WxGoodsListData;
import com.cskaoyan.bean.goods.wx.WxGoodsRelatedData;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.wx.footprint.FootPritnByIdVo;
import com.cskaoyan.service.wx.WxCategoryService;
import com.cskaoyan.service.wx.WxGoodsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: WxGoodsController
 * Description:
 * date: 2022/6/8 14:45
 *
 * @author bruce
 * @since JDK 8
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    WxGoodsService wxGoodsService;

    @Autowired
    WxCategoryService categoryService;

    @RequestMapping("count")
    public BaseRespVo goodsCount() {
        long count = wxGoodsService.wxQueryCount();
        return BaseRespVo.ok(count);
    }

    @RequestMapping("category")
    public BaseRespVo goodsCategory(Integer id) {
        WxGoodsCategoryData wxGoodsCategoryData = categoryService.wxGoodsCategoryquery(id);
        return BaseRespVo.ok(wxGoodsCategoryData);
    }

    @Transactional
    @RequestMapping("list")
    public BaseRespVo goodsList(BaseParam param, Integer categoryId, String keyword) {
        if (StringUtils.isEmpty(keyword)) {
            WxGoodsListData wxGoodsListData = wxGoodsService.wxQuery(param, categoryId);
            return BaseRespVo.ok(wxGoodsListData);
        } else {
            WxGoodsListData wxGoodsListData = wxGoodsService.wxQuery2(param, keyword,categoryId);
            return BaseRespVo.ok(wxGoodsListData);
        }
    }

    @RequestMapping("related")
    public BaseRespVo goodsRelated(Integer id) {
        WxGoodsRelatedData wxGoodsRelatedData = wxGoodsService.wxQueryRelated(id);
        return BaseRespVo.ok(wxGoodsRelatedData);
    }

    /**
     * @Description:借壳
     * @return:
     * @Author: 蒋镇泽
     * @Date: 2022/6/8 17:26
     */
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        FootPritnByIdVo footPrintVo = wxGoodsService.wxQueryById(id);
        return BaseRespVo.ok(footPrintVo);

    }

}
